using UnityEngine;

public class TeamMateTag : MonoBehaviour
{
	public UILabel indexLabel;

	public UITexture avatarTexture;

	public UISprite fillSprite;

	public UILabel starsCountLabel;

	public UILabel starRankLabel;

	public UILabel nameLabel;

	public UILabel levelNameLabel;

	private GGServerRequestsBackend.TextureRequest textureRequest;

	public void Init(int index, string name, string avatarURL, int starsCollected)
	{
		indexLabel.text = (index + 1).ToString();
		nameLabel.text = name;
		if (textureRequest == null || textureRequest.url != avatarURL)
		{
			textureRequest = new GGServerRequestsBackend.TextureRequest(avatarURL);
			textureRequest.cache = CacheStategy.CacheToFile;
			textureRequest.onComplete = OnRequestComplete;
			BehaviourSingleton<GGRequestLimitter>.instance.Add(textureRequest);
		}
		LevelSystem.CurrentDefinedPointLevelInfo currentDefinedPointLevelInfo = LevelSystem.instance.PlayerLevelForXP(starsCollected);
		fillSprite.fillAmount = currentDefinedPointLevelInfo.subProgress;
		starsCountLabel.text = starsCollected.ToString();
		starRankLabel.text = (currentDefinedPointLevelInfo.levelIndex + 1).ToString();
		levelNameLabel.text = currentDefinedPointLevelInfo.definedPoint.levelName;
	}

	public void OnRequestComplete(GGServerRequestsBackend.ServerRequest request)
	{
		GGServerRequestsBackend.TextureRequest textureRequest = request as GGServerRequestsBackend.TextureRequest;
		if (textureRequest != null && textureRequest == this.textureRequest)
		{
			if (request.status != 0)
			{
				this.textureRequest = null;
			}
			else
			{
				avatarTexture.mainTexture = textureRequest.response;
			}
		}
	}
}
